<template>
    <div>
        <!-- 面包屑区域 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片视图 -->
        <el-card>
         <!-- 用户搜索框 -->
         <el-row>
           <el-col :span="8">
             <el-input placeholder="请输入内容" ><el-button slot="append" icon="el-icon-search" ></el-button></el-input>
           </el-col>
         </el-row>
        <!-- 表格 -->
        <el-table :data="orderList" border stripe>
            <el-table-column label="订单编号" prop="order_number" ></el-table-column>
            <el-table-column label="订单价格" prop="order_price" ></el-table-column>
            <el-table-column label="是否付款" prop="order_pay" >
                <template slot-scope="scope">
                    <el-button type="warning" v-if="scope.row.order_pay==0" plain>未付款</el-button>
                    <el-button type="success" v-if="scope.row.order_pay==1" plain>已付款</el-button>
                </template>
            </el-table-column>
            <el-table-column label="是否发货" prop="is_send" ></el-table-column>
            <el-table-column label="下单时间" prop="create_time" ></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                     <el-tooltip :enterable="false" class="item" effect="dark" content="修改订单地址" placement="top-start">
                        <el-button type="primary" size="small" @click="editAddress()"><i class="el-icon-edit"></i></el-button>
                     </el-tooltip>
                     <el-tooltip :enterable="false" class="item" effect="dark" content="查看订单进度" placement="top-start">
                        <el-button type="success" size="small" @click="progressClick()"><i class="el-icon-search"></i></el-button>
                     </el-tooltip>
                     
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryInfo.pagenum"
            :page-sizes="[5, 7, 9, 10]"
            :page-size="queryInfo.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
        title="修改地址"
        :visible.sync="editDialogVisible"
        width="50%"
       >
       <!-- 表单 -->
        <el-form :ref="addressForm" :model="addressForm" :rules="addressFormRules">
            <el-form-item label="省市区/县" prop="address1">
                <el-cascader
                    v-model="addressForm.address1"
                    :options="CityData"
                    :props="{ expandTrigger: 'hover' }"
                    @change="handleChange">
                </el-cascader>
            </el-form-item>
             <el-form-item label="详细地址" prop="address2">
                <el-input v-model="addressForm.address2"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="editDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitAddress">确 定</el-button>
        </span>
        </el-dialog>
        <!-- 查看物流进度 -->
        <el-dialog
            title="物流进度"
            :visible.sync="progressDialogVisible"
            width="50%"
            @click="progressClosed"
            >
            <!-- 时间轴 -->
            <el-timeline>
                <el-timeline-item
                v-for="(activity, index) in progressList"
                :key="index"
                :timestamp="activity.ftime">
                {{activity.context}}
                </el-timeline-item>
            </el-timeline>
            <span slot="footer" class="dialog-footer">
                <el-button @click="progressDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="progressDialogVisible = false">确 定</el-button>
            </span>
            </el-dialog>

    </div>
</template>
<script>
import CityData from './citydata'
export default {
    data(){
        return{
            queryInfo:{
                query:'',
                pagenum:1,
                pagesize:10
            },
            editDialogVisible:false,
            orderList:[],
            total:0,
            addressForm:{
                address1:[],
                address2:''
            },
            progressList:[],
            CityData,
            progressDialogVisible:false,
            addressFormRules:{
                address1:[
                     { required: true, message: '请选择收货地址', trigger: 'blur' },
                ],
                address2:[
                     { required: true, message: '请输入详细地址', trigger: 'blur' },
                ],
            },
          
        }
    },
    created(){
        this.getOrdersList();
    },
    methods:{
        //获取订单列表数据
        async getOrdersList(){
            var {data:res}=await this.$http.get('orders',{params:this.queryInfo})
            this.orderList=res.data.goods;
            this.total=res.data.total;
        },
        //分页
        handleSizeChange(pagesize){
            this.queryInfo.pagesize=pagesize;
            this.getOrdersList();
        },
        handleCurrentChange(val){
           this.queryInfo.pagenum=val;
           this.getOrdersList();
        },
        // 修改收货地址
        editAddress(){
            this.editDialogVisible=true;
        },
        //选择地址
        handleChange(){

        },
        submitAddress(){
            this.editDialogVisible=false;
        },
        //查看物流进度
        async progressClick(){
            //获取物流进度
           var {data:res}=await this.$http.get('/kuaidi/1106975712662')
           if(res.meta.status!==200) return this.$message.error('获取物流数据失败')
           this.progressList=res.data;
           console.log(this.progressList)
            this.progressDialogVisible=true;
        },
        //关闭progress对话框
        progressClosed(){
            this.progressDialogVisible=false;
            this.progressList=[];
        }
    }
}
</script>
<style lang="less" scoped>
.el-cascader{
    width: 100%;
}
</style>